package com.yuyue.dronesystem.services.impls;

import java.util.List;
import java.util.Optional;

import com.yuyue.dronesystem.entities.User;
import com.yuyue.dronesystem.repository.UserRepository;
import com.yuyue.dronesystem.services.UserService;
import com.yuyue.dronesystem.utils.myMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * UserServiceImpl
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserRepository userRepository;

    @Override
    public List<User> getUsers() {
        List<User> users = userRepository.findAll();
        return users;
    }

    @Override
    public User getUser(Integer id) {
        Optional<User> user = userRepository.findById(id);
        return user.get();
    }

    @Override
    public User saveUser(User user) {
        userRepository.save(user);
        return user;
    }

    @Override
    public Boolean deleteUser(Integer id) {
        userRepository.deleteById(id);
        return null;
    }
}